From: Matthew Daley Date: Mon, 12 Nov 2012 17:03:21 +0000 (+0000) Subject: pygrub: Fix command line argument error handling X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~7666 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks://%22Dat/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22Dat?a=commitdiff_plain;h=0c6601ee18c664a8702c142bd901ebc9539ac48d;p=xen.git pygrub: Fix command line argument error handling pygrub's individual config file parsers do not correctly check the amount of command line arguments given to them. In addition, the LILO config parser would report an incorrect message. Use len() to correctly check the amount of arguments, and fix the LILO error message. Signed-off-by: Matthew Daley Acked-by: Ian Campbell Committed-by: Ian Campbell --- diff --git a/tools/pygrub/src/ExtLinuxConf.py b/tools/pygrub/src/ExtLinuxConf.py index 19776a3c92..510099bf59 100644 --- a/tools/pygrub/src/ExtLinuxConf.py +++ b/tools/pygrub/src/ExtLinuxConf.py @@ -207,7 +207,7 @@ class ExtLinuxConfigFile(object): } if __name__ == "__main__": - if sys.argv < 2: + if len(sys.argv) < 2: raise RuntimeError, "Need a configuration file to read" g = ExtLinuxConfigFile(sys.argv[1]) for i in g.images: diff --git a/tools/pygrub/src/GrubConf.py b/tools/pygrub/src/GrubConf.py index c4f543d196..629951f941 100644 --- a/tools/pygrub/src/GrubConf.py +++ b/tools/pygrub/src/GrubConf.py @@ -454,7 +454,7 @@ class Grub2ConfigFile(_GrubConfigFile): } if __name__ == "__main__": - if sys.argv < 3: + if len(sys.argv) < 3: raise RuntimeError, "Need a grub version (\"grub\" or \"grub2\") and a grub.conf or grub.cfg to read" if sys.argv[1] == "grub": g = GrubConfigFile(sys.argv[2]) diff --git a/tools/pygrub/src/LiloConf.py b/tools/pygrub/src/LiloConf.py index 9858ae26f5..2cb649f115 100644 --- a/tools/pygrub/src/LiloConf.py +++ b/tools/pygrub/src/LiloConf.py @@ -169,8 +169,8 @@ class LiloConfigFile(object): } if __name__ == "__main__": - if sys.argv < 2: - raise RuntimeError, "Need a grub.conf to read" + if len(sys.argv) < 2: + raise RuntimeError, "Need a lilo.conf to read" g = LiloConfigFile(sys.argv[1]) for i in g.images: print i #, i.title, i.root, i.kernel, i.args, i.initrd